{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "8H17bBI3N-vo"
      },
      "source": [
        "\n",
        "\n",
        "## RapidOCR Python Demo\n",
        "\n"
      ]
    },
    {
      "attachments": {},
      "cell_type": "markdown",
      "metadata": {
        "id": "0qapeJlG6JFJ"
      },
      "source": [
        "#### pip Install"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "metadata": {
        "id": "sTB1PsMp6XTT"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Looking in indexes: https://pypi.douban.com/simple/\n",
            "Collecting rapidocr_onnxruntime\n",
            "  Downloading https://pypi.doubanio.com/packages/c5/ed/16c0d4c909ea626d35923d913295394f2ff40f605cd4036cb9d8ae7eab62/rapidocr_onnxruntime-1.1.18-py3-none-any.whl (12.3 MB)\n",
            "     ---------------------------------------- 12.3/12.3 MB 2.7 MB/s eta 0:00:00\n",
            "Requirement already satisfied: numpy>=1.19.3 in e:\\anaconda3\\envs\\demo\\lib\\site-packages (from rapidocr_onnxruntime) (1.21.6)\n",
            "Requirement already satisfied: Shapely>=1.7.1 in e:\\anaconda3\\envs\\demo\\lib\\site-packages (from rapidocr_onnxruntime) (1.8.1.post1)\n",
            "Requirement already satisfied: opencv-python>=4.5.1.48 in e:\\anaconda3\\envs\\demo\\lib\\site-packages (from rapidocr_onnxruntime) (4.6.0.66)\n",
            "Requirement already satisfied: six>=1.15.0 in e:\\anaconda3\\envs\\demo\\lib\\site-packages (from rapidocr_onnxruntime) (1.16.0)\n",
            "Requirement already satisfied: onnxruntime>=1.7.0 in e:\\anaconda3\\envs\\demo\\lib\\site-packages (from rapidocr_onnxruntime) (1.10.0)\n",
            "Requirement already satisfied: pyclipper>=1.2.1 in e:\\anaconda3\\envs\\demo\\lib\\site-packages (from rapidocr_onnxruntime) (1.2.1)\n",
            "Requirement already satisfied: protobuf in e:\\anaconda3\\envs\\demo\\lib\\site-packages (from onnxruntime>=1.7.0->rapidocr_onnxruntime) (3.20.0)\n",
            "Requirement already satisfied: flatbuffers in e:\\anaconda3\\envs\\demo\\lib\\site-packages (from onnxruntime>=1.7.0->rapidocr_onnxruntime) (2.0)\n",
            "Installing collected packages: rapidocr_onnxruntime\n",
            "Successfully installed rapidocr_onnxruntime-1.1.18\n"
          ]
        },
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "'wget' �����ڲ����ⲿ���Ҳ���ǿ����еĳ���\n",
            "���������ļ���\n"
          ]
        }
      ],
      "source": [
        "!pip install rapidocr_onnxruntime -i https://pypi.douban.com/simple/\n",
        "!wget -O 2.jpg https://pic1.zhimg.com/v2-612e2d58bd9f5f4a99c448a4d626ce86_1440w.jpg?source=172ae18b"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "PDlCLO_CewSk"
      },
      "source": [
        "#### Run as code"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 9,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 393
        },
        "id": "bbHGS0emSNTz",
        "outputId": "2a42df96-4962-463d-89fc-0cad8bdcd8d5"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "[[[58.0, 136.0], [482.0, 136.0], [482.0, 178.0], [58.0, 178.0]], '这时我看见他的背影，', '0.8524695634841919']\n",
            "[[[58.0, 214.0], [540.0, 216.0], [540.0, 258.0], [58.0, 256.0]], '我的泪很快地流下来了。', '0.8891244679689407']\n",
            "[[[57.0, 294.0], [396.0, 296.0], [396.0, 338.0], [57.0, 336.0]], '我赶紧干了泪，', '0.793162614107132']\n",
            "[[[59.0, 375.0], [253.0, 375.0], [253.0, 418.0], [59.0, 418.0]], '怕他看见，', '0.7794817586739858']\n",
            "[[[60.0, 455.0], [350.0, 457.0], [350.0, 497.0], [59.0, 495.0]], '也怕别人看见。', '0.8421911969780922']\n",
            "[[[70.0, 569.0], [189.0, 569.0], [189.0, 607.0], [70.0, 607.0]], '《背影》', '0.7730599045753479']\n"
          ]
        }
      ],
      "source": [
        "import cv2\n",
        "from rapidocr_onnxruntime import RapidOCR\n",
        "\n",
        "rapid_ocr = RapidOCR()\n",
        "\n",
        "image_path = '2.jpg'\n",
        "img = cv2.imread(image_path)\n",
        "ocr_result, _ = rapid_ocr(img)\n",
        "\n",
        "for v in ocr_result:\n",
        "    print(v)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 4,
      "metadata": {
        "id": "nzSxM43V9rAL"
      },
      "outputs": [],
      "source": []
    }
  ],
  "metadata": {
    "colab": {
      "collapsed_sections": [],
      "name": "Copy of Copy of RapidOCRDemo.ipynb",
      "provenance": []
    },
    "kernelspec": {
      "display_name": "demo",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.13"
    },
    "vscode": {
      "interpreter": {
        "hash": "d42ac74e361e91c495bc3239dc10e7028f0ad770b2a1f806c814d17578354ad7"
      }
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
